//
//  ZJMessagePunishViewController.m
//  ZJControlsClass
//
//  Created by wandoufo on 2024/12/6.
//

#import "ZJMessagePunishViewController.h"

@interface ZJMessagePunishViewController ()

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) UILabel *nameLabel;         // 被处罚人
@property (nonatomic, strong) UILabel *timeLabel;         // 处罚时间
@property (nonatomic, strong) UILabel *reasonLabel;       // 处罚说明
@property (nonatomic, strong) NSMutableArray *recordViews; // 处罚记录视图数组


@end

@implementation ZJMessagePunishViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"处罚详情";
    self.view.backgroundColor = [UIColor whiteColor];
    self.recordViews = [NSMutableArray array];
    
    [self setupUI];
}

- (void)setupUI {
    // 创建滚动视图
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    [self.view addSubview:scrollView];
    self.scrollView = scrollView;
    
    UIView *contentView = [[UIView alloc] init];
    [scrollView addSubview:contentView];
    self.contentView = contentView;
    
    // 设置基本信息
    [self setupBasicInfo];
    
    // 设置处罚记录
    [self setupPunishRecords];
    
    // 设置约束
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(scrollView);
        make.width.equalTo(scrollView);
    }];
}

- (void)setupBasicInfo {
    // 被处罚人
    UIView *nameView = [[UIView alloc] init];
    [self.contentView addSubview:nameView];
    
    UILabel *nameTitleLabel = [[UILabel alloc] init];
    nameTitleLabel.text = @"被处罚：";
    nameTitleLabel.textAlignment = NSTextAlignmentRight;
    nameTitleLabel.font = [UIFont systemFontOfSize:14];
    [nameView addSubview:nameTitleLabel];
    
    UILabel *nameContentLabel = [[UILabel alloc] init];
    nameContentLabel.text = @"赵庄镇";
    nameContentLabel.font = [UIFont systemFontOfSize:14];
    [nameView addSubview:nameContentLabel];
    self.nameLabel = nameContentLabel;
    
    // 处罚时间
    UIView *timeView = [[UIView alloc] init];
    [self.contentView addSubview:timeView];
    
    UILabel *timeTitleLabel = [[UILabel alloc] init];
    timeTitleLabel.text = @"处罚时间：";
    timeTitleLabel.textAlignment = NSTextAlignmentRight;
    timeTitleLabel.font = [UIFont systemFontOfSize:14];
    [timeView addSubview:timeTitleLabel];
    
    UILabel *timeContentLabel = [[UILabel alloc] init];
    timeContentLabel.text = @"2024-12-04 09:13:49";
    timeContentLabel.font = [UIFont systemFontOfSize:14];
    [timeView addSubview:timeContentLabel];
    self.timeLabel = timeContentLabel;
    
    // 处罚说明
    UIView *reasonView = [[UIView alloc] init];
    [self.contentView addSubview:reasonView];
    
    UILabel *reasonTitleLabel = [[UILabel alloc] init];
    reasonTitleLabel.text = @"处罚说明：";
    reasonTitleLabel.textAlignment = NSTextAlignmentRight;
    reasonTitleLabel.font = [UIFont systemFontOfSize:14];
    [reasonView addSubview:reasonTitleLabel];
    
    UILabel *reasonContentLabel = [[UILabel alloc] init];
    reasonContentLabel.text = @"不按规定佩戴或放置控制区通行证的，或者不接受证件检查的";
    reasonContentLabel.numberOfLines = 0;
    reasonContentLabel.font = [UIFont systemFontOfSize:14];
    [reasonView addSubview:reasonContentLabel];
    self.reasonLabel = reasonContentLabel;
    
    // 设置约束
    [nameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(15);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
    }];
    
    [nameTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(nameView);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(28);
    }];
    
    [nameContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameTitleLabel.mas_right);
        make.right.top.bottom.equalTo(nameView);
    }];
    
    [timeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameView.mas_bottom).offset(10);
        make.left.right.equalTo(nameView);
    }];
    
    [timeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(timeView);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(28);
    }];
    
    [timeContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(timeTitleLabel.mas_right);
        make.right.top.bottom.equalTo(timeView);
    }];
    
    [reasonView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(timeView.mas_bottom).offset(10);
        make.left.right.equalTo(timeView);
    }];
    
    [reasonTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(reasonView);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(28);
    }];
    
    [reasonContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(reasonTitleLabel.mas_right);
        make.right.top.bottom.equalTo(reasonView);
    }];
}

- (void)setupPunishRecords {
    UIView *lastView = self.reasonLabel;
    
    for (int i = 1; i <= 3; i++) {
        UIView *recordView = [self createPunishRecordWithIndex:i];
        [self.contentView addSubview:recordView];
        [self.recordViews addObject:recordView];
        
        [recordView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lastView.mas_bottom).offset(20);
            make.left.equalTo(self.contentView).offset(15);
            make.right.equalTo(self.contentView).offset(-15);
        }];
        
        lastView = recordView;
    }
    
    // 设置contentView的底部约束
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(lastView.mas_bottom).offset(20);
    }];
}

- (UIView *)createPunishRecordWithIndex:(NSInteger)index {
    UIView *recordView = [[UIView alloc] init];
    recordView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0];
    recordView.layer.cornerRadius = 8;
    
    // 标题
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = [NSString stringWithFormat:@"处罚记录%ld", (long)index];
    titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    [recordView addSubview:titleLabel];
    
    // 处罚方式标题
    UILabel *methodTitleLabel = [[UILabel alloc] init];
    methodTitleLabel.text = @"处罚方式：";
    methodTitleLabel.font = [UIFont systemFontOfSize:14];
    [recordView addSubview:methodTitleLabel];
    
    // 处罚方式内容
    UILabel *methodContentLabel = [[UILabel alloc] init];
    methodContentLabel.text = @"扣分:-2; 罚款:10元; 加入黑名单";
    methodContentLabel.font = [UIFont systemFontOfSize:14];
    methodContentLabel.numberOfLines = 0;
    [recordView addSubview:methodContentLabel];
    
    // 处罚原因标题
    UILabel *reasonTitleLabel = [[UILabel alloc] init];
    reasonTitleLabel.text = @"处罚原因：";
    reasonTitleLabel.font = [UIFont systemFontOfSize:14];
    [recordView addSubview:reasonTitleLabel];
    
    // 处罚原因内容
    UILabel *reasonContentLabel = [[UILabel alloc] init];
    reasonContentLabel.text = @"不按规定佩戴或放置控制区通行证的，或者不接受证件检查的";
    reasonContentLabel.font = [UIFont systemFontOfSize:14];
    reasonContentLabel.numberOfLines = 0;
    [recordView addSubview:reasonContentLabel];
    
    // 设置约束
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(recordView).offset(15);
        make.left.equalTo(recordView).offset(15);
        make.right.equalTo(recordView).offset(-15);
    }];
    
    [methodTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom).offset(10);
        make.left.equalTo(recordView).offset(15);
        make.width.mas_equalTo(70);
    }];
    
    [methodContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(methodTitleLabel);
        make.left.equalTo(methodTitleLabel.mas_right);
        make.right.equalTo(recordView).offset(-15);
    }];
    
    [reasonTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(methodContentLabel.mas_bottom).offset(10);
        make.left.equalTo(recordView).offset(15);
        make.width.mas_equalTo(70);
    }];
    
    [reasonContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(reasonTitleLabel);
        make.left.equalTo(reasonTitleLabel.mas_right);
        make.right.equalTo(recordView).offset(-15);
        make.bottom.equalTo(recordView).offset(-15);
    }];
    
    return recordView;
}


@end
